    SET NOCOUNT ON
    
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Maintenance' AND xtype='U')
        DROP TABLE "Maintenance"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Evaluations' AND xtype='U')
        DROP TABLE "Evaluations"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Evaluations_Submissions' AND xtype='U')
        DROP TABLE "Evaluations_Submissions"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Relations_Evaluations-Courses_Section' AND xtype='U')
        DROP TABLE "Relations_Evaluations-Courses_Section"

    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'ScheduledEventQueues' AND xtype='U')
        DROP TABLE "ScheduledEventQueues"
                
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Stats_LearnObjs' AND xtype='U')
        DROP TABLE "Stats_LearnObjs"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Stats_Quiz_Questions' AND xtype='U')
        DROP TABLE "Stats_Quiz_Questions"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Assignments_Submission_Essay_Comments' AND xtype='U')
        DROP TABLE "Assignments_Submission_Essay_Comments"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Assignments_Submission_Essay' AND xtype='U')
        DROP TABLE "Assignments_Submission_Essay"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Assignments_Submission_Quiz' AND xtype='U')
        DROP TABLE "Assignments_Submission_Quiz"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Assignments_Quiz' AND xtype='U')
        DROP TABLE "Assignments_Quiz"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Relations_Assignments-Courses_Section' AND xtype='U')
        DROP TABLE "Relations_Assignments-Courses_Section"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Assignments' AND xtype='U')
        DROP TABLE "Assignments"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Relations_LearnObj-Standard' AND xtype='U')
        DROP TABLE "Relations_LearnObj-Standard"    
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Relations_Course-User' AND xtype='U')
        DROP TABLE "Relations_Course-User"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Log_Error_UserReport' AND xtype='U')
        DROP TABLE Log_Error_UserReport
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Log_Error' AND xtype='U')
        DROP TABLE Log_Error
    
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Users_NonInstitute_Activation' AND xtype='U')
        DROP TABLE "Users_NonInstitute_Activation"
            
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Users_Stats_Login' AND xtype='U')
        DROP TABLE "Users_Stats_Login"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Users_Institute_Students' AND xtype='U')
        DROP TABLE "Users_Institute_Students"
    
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Users_NonInstitute' AND xtype='U')
        DROP TABLE "Users_NonInstitute"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses_LearnObj_Section' AND xtype='U')
        DROP TABLE "Courses_LearnObj_Section"
            
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses_LearnObj' AND xtype='U')
        DROP TABLE "Courses_LearnObj"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses_Standard_Section' AND xtype='U')
        DROP TABLE "Courses_Standard_Section"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses_Section' AND xtype='U')
        DROP TABLE "Courses_Section"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses_Standard' AND xtype='U')
        DROP TABLE "Courses_Standard"
    
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Standards' AND xtype='U')
        DROP TABLE "Standards"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'LearnObjs' AND xtype='U')
        DROP TABLE "LearnObjs"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Courses' AND xtype='U')
        DROP TABLE "Courses"
        
    IF EXISTS(SELECT name FROM sysobjects WHERE name = N'Users' AND xtype='U')
        DROP TABLE "Users"
    
    
    CREATE TABLE "Courses" (
        "CourseID"                    "int"            IDENTITY (1, 1) NOT NULL,
        "Title"                        varchar(50)    NOT NULL,
            /* ex: Engl 101: Introductory Writing */
        "Subtitle"                    varchar(50)    NULL, 
            /* ex: Libraries Online Tour and Quiz */
        "Introduction"                "text"            NULL,
            /* Goes under the title and subtitle on class.aspx page. */
        "IsEnabled"                    "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses" PRIMARY KEY CLUSTERED
        (
            "CourseID"
        )
    )
    
        
    /* This Table is to customize section information */
    CREATE TABLE "Courses_Section" (
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "UseSectionInfo"            "bit"            NOT NULL DEFAULT (0),
            /* If enabled, app will load class information from this table. */
        "Subtitle"                    varchar(50)    NULL,
            /* ex: Libraries Online Tour and Quiz */
        "Introduction"                "text"            NULL,
        "ClassTime"                    varchar(30)        NULL,
            /* ex: MWF 11:10 - 12:00 */
        "IsEnabled"                    "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses_Section" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "SectionNumber"
        ),
        CONSTRAINT "FK_Courses_Section-Course" FOREIGN KEY 
        (
            "CourseID"
        ) REFERENCES "dbo"."Courses" (
            "CourseID"
        ) ON DELETE CASCADE
    )
    
        
    CREATE TABLE "Standards" (
        "StandardID"                "int"            IDENTITY (1, 1) NOT NULL PRIMARY KEY,
        "Standard"                    varchar(50)        NOT NULL
    )
    

    /* Course's default Standard */
    CREATE TABLE "Courses_Standard" (
        "CourseID"                    "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
            /* For WSU, between 1 to 4 */
        "IntroTitle"                varchar(50)        NULL,
            /* If ASI is enabled, at the top of the standard box, it will show a link named this field's value. 
               ex: Assignment  or Intro to this Standard */
        "IntroContent"                "text"            NULL,
            /* If ASI is enabled, it will show users what this Standard is about.
               ex: Needed Information Standard will teach you how to determine what you need for your paper!  */
        "IsIntroEnabled"            "bit"            NOT NULL DEFAULT(1),
        "IsStandardEnabled"            "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses_Standard" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "StandardID"
        ),
        CONSTRAINT "FK_Courses_Standard-Courses" FOREIGN KEY 
        (
            "CourseID"
        ) REFERENCES "dbo"."Courses" (
            "CourseID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_Standard-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        )
    )
    
    
    
    CREATE TABLE "Courses_Standard_Section" (
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "UseSectionInfo"            "bit"            NOT NULL DEFAULT (0),
        "IntroTitle"                varchar(50)        NULL,
        "IntroContent"                "text"            NULL,
        "IsIntroEnabled"            "bit"            NOT NULL DEFAULT(1),
        "IsStandardEnabled"            "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses_Standard_Section" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "SectionNumber",
            "StandardID"
        ),
        CONSTRAINT "FK_Courses_Standard_Section-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber" 
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_Standard_Section-Standard" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        )
    )
    
    
    
    CREATE TABLE "LearnObjs" (
        "LearnObjID"                "int"            NOT NULL IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
        "Title"                        varchar(100)    NOT NULL,
        "Instruction"                "text"            NOT NULL,
        "EstimatedTime"                varchar(20)        NOT NULL DEFAULT (0),
        "Link"                        varchar(150)        NULL,
        "LearnObjQuizQuestions"        "xml"            NULL,
        "LastUpdateDateTime"        "datetime"        NULL DEFAULT(getdate())
    )
    
    
    
    CREATE TABLE "Courses_LearnObj" (
        "CourseID"                    "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "LearnObjID"                "int"            NOT NULL,
        "SortOrder"                    "int"            NOT NULL DEFAULT(1),
        "UseAlterInfo"                "bit"            NOT NULL DEFAULT(0),
            /* 'Use Alternate LearnObj Information (such as Title and Description of LearnObj)?'
                If true, it will display AlterTitle and Alter Description's value
                    instead of Default Title and Description from LearnObjs table. */
        "AlterTitle"                varchar(50)        NULL,
        "AlterDescription"            "text"            NULL,
        "IsEnabled"                    "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses_LearnObj" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "StandardID",
            "LearnObjID"
        ),
        CONSTRAINT "FK_Courses_LearnObj-Courses" FOREIGN KEY 
        (
            "CourseID"
        ) REFERENCES "dbo"."Courses" (
            "CourseID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_LearnObj-LearnObjs" FOREIGN KEY 
        (
            "LearnObjID"
        ) REFERENCES "dbo"."LearnObjs" (
            "LearnObjID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_LearnObj-Standard" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        )
    )
    
    
    
    CREATE TABLE "Courses_LearnObj_Section" (
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "LearnObjID"                "int"            NOT NULL,
        "SortOrder"                    "int"            NOT NULL DEFAULT(1),
        "UseAlterInfo"                "bit"            NOT NULL DEFAULT(0),
            /* Allows user to customize LearnObj Information by Section*/
        "AlterTitle"                varchar(50)        NULL,    
        "AlterDescription"            "text"            NULL,
        "IsEnabled"                    "bit"            NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Courses_LearnObj_Section" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "SectionNumber",
            "StandardID",
            "LearnObjID"
        ),
        CONSTRAINT "FK_Courses_LearnObj-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_LearnObj_Section-LearnObjs" FOREIGN KEY 
        (
            "LearnObjID"
        ) REFERENCES "dbo"."LearnObjs" (
            "LearnObjID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Courses_LearnObj_Section-Standard" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        )
    )
    
    
    
    CREATE TABLE "Users" (
        "UserID"                    "int"                IDENTITY (1, 1) NOT NULL,
        "Username"                    varchar(100)        NOT NULL,
        "AccountType"                varchar(15)            NOT NULL,
            /* Instructor, Student, NonInstitute */
        "FirstName"                    varchar(50)            NULL,
        "LastName"                    varchar(50)            NULL,
        "Email"                        varchar(100)        NULL,
        "StudentIDNumber"            varchar(50)            NULL,
        "Year"                        "int"                NULL,
            /* 1 - Freshmen, 2 - Sophomore, 3 - Junior, 4 - Senior, 0 - N/A */
        "IsEnabled"                    "bit"                NOT NULL DEFAULT(1),
        CONSTRAINT "PK_Users" PRIMARY KEY CLUSTERED
        (
            "UserID"
        )
    )
    
    
    
    CREATE TABLE "Users_NonInstitute" (
        "UserID"                    "int"                NOT NULL,
        "Password"                    varchar(100)        NOT NULL,
        "Organization"                varchar(50)            NULL,
        "SecurityQuestion"            varchar(50)            NULL,
        "SecurityAnswer"            varchar(20)            NULL,
        CONSTRAINT "PK_Users_NonInstitute" PRIMARY KEY CLUSTERED
        (
            "UserID"
        ),
        CONSTRAINT "FK_Users_NonInstitute-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Users_NonInstitute_Activation" (
        "UserID"                    "int"                NOT NULL,
        "ActivationCode"            varchar(50)            NOT NULL,
        CONSTRAINT "PK_Users_NonInstitute_Activation" PRIMARY KEY CLUSTERED
        (
            "UserID"
        ),
        CONSTRAINT "FK_Users_NonInstitute_Activation-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Users_Stats_Login" (
        "StatsLoginID"                "int"            IDENTITY(1, 1) NOT NULL PRIMARY KEY CLUSTERED,
        "UserID"                    "int"            NOT NULL,
        "LoginDateTime"                "datetime"        NOT NULL,
        "LogoutDateTime"            "datetime"        NULL,
        "IpAddress"                    varchar(40)        NULL,
            /* varchar(40) has huge size to in case of IPv6 */
        "OS"                        varchar(30)        NULL,
        "Browser"                    varchar(30)        NULL,
        CONSTRAINT "FK_Users_Stats_Login-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )


    
    CREATE TABLE "Log_Error" (
        "LogErrorID"                "int"            IDENTITY (1, 1) NOT NULL PRIMARY KEY CLUSTERED,
        "UserID"                    "int"            NULL,
        "ErrorType"                    varchar(200)    NULL,
        "ErrorMessage"                "text"            NULL,
        "OS"                        varchar(50)        NULL,
        "Browser"                    varchar(50)        NULL,
        "Severity"                    "tinyint"        NOT NULL DEFAULT(3),
        "TimeStamp"                    "datetime"        NOT NULL DEFAULT(getdate()),
        CONSTRAINT "FK_Log_Error-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )
        
        
        
    CREATE TABLE "Log_Error_UserReport" (
        "LogErrorID"                "int"            NOT NULL PRIMARY KEY,
        "UserReport"                "text"            NOT NULL,
        CONSTRAINT "FK_Log_Error_UserReport-Log_Error" FOREIGN KEY 
        (
            "LogErrorID"
        ) REFERENCES "dbo"."Log_Error" (
            "LogErrorID"
        ) ON DELETE CASCADE
    )    

        
        
    CREATE TABLE "Relations_Course-User" (
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "UserID"                    "int"            NOT NULL,
        "Type"                        varchar(20)        NOT NULL,
            /* ex: Instructor, Student */
        "SortOrder"                    "int"            NULL,
        CONSTRAINT "PK_Relations_Course-User" PRIMARY KEY CLUSTERED
        (
            "CourseID",
            "SectionNumber",
            "UserID"
        ),
        CONSTRAINT "FK_Relations_Course_User-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"    
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"    
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Relations_Course_User-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Relations_LearnObj-Standard" (
        "LearnObjID"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        CONSTRAINT "PK_Relations_LearnObj-Standard" PRIMARY KEY CLUSTERED
        (
            "LearnObjID",
            "StandardID"
        ),
        CONSTRAINT "FK_Relations_LearnObj_Standard-LearnObjs" FOREIGN KEY 
        (
            "LearnObjID"
        ) REFERENCES "dbo"."LearnObjs" (
            "LearnObjID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Relations_LearnObj_Standard-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Assignments" (
        "AssignmentID"                "int"                IDENTITY(1, 1) NOT NULL,
        "AssignmentType"            varchar(10)            NOT NULL,
            /* i.e. Quiz, Essay*/
        "AssignmentTitle"            varchar(100)        NOT NULL,
        "Instruction"                "text"                NULL,
        "SendNotifyStart"            "bit"                NOT NULL DEFAULT(0),
        "SendNotifyEnd"                "bit"                NOT NULL DEFAULT(0),
        "SendNotifyEndHours"        "int"                NOT NULL DEFAULT(24),
        "SendResult"                "bit"                NOT NULL DEFAULT(1),
        "TimeStamp"                    "datetime"            NOT NULL DEFAULT(getdate()),
        "StartDateTime"                "datetime"            NOT NULL DEFAULT(getdate()),
        "EndDateTime"                "datetime"            NULL,
        CONSTRAINT "PK_Assignments" PRIMARY KEY CLUSTERED
        (
            "AssignmentID"
        )
    )
    
    
    
    CREATE TABLE "Assignments_Quiz" (
        "AssignmentID"                "int"            NOT NULL,
        "QuizAssignment"            "text"            NOT NULL,
        "MaximumAttempts"            "int"            NOT NULL,
        "NumberOfQuestions"            "int"            NOT NULL,
        CONSTRAINT "PK_Assignments_Quiz" PRIMARY KEY CLUSTERED
        (
            "AssignmentID"
        ),
        CONSTRAINT "FK_Assignments_Quiz-Assignments" FOREIGN KEY 
        (
            "AssignmentID"
        ) REFERENCES "dbo"."Assignments" (
            "AssignmentID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Relations_Assignments-Courses_Section" (
        "AssignmentID"                "int"                NOT NULL,
        "CourseID"                    "int"                NOT NULL,
        "SectionNumber"                "int"                NOT NULL,
        "StandardID"                "int"                NOT NULL,
        CONSTRAINT "PK_Relations_Assignments_Courses_Section" PRIMARY KEY CLUSTERED
        (
            "AssignmentID",
            "CourseID",
            "SectionNumber",
            "StandardID"
        ),
        CONSTRAINT "FK_Relations_Assignments_Courses_Section-Assignments" FOREIGN KEY 
        (
            "AssignmentID"
        ) REFERENCES "dbo"."Assignments" (
            "AssignmentID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Relations_Assignments_Courses_Section-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Relations_Assignments_Course_Sections-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        ) ON DELETE CASCADE
    )
    
    
    
    CREATE TABLE "Assignments_Submission_Quiz" (
        "QuizSubmissionID"            "int"            IDENTITY(1, 1) NOT NULL,
        "AssignmentID"                "int"            NOT NULL,
        "UserID"                    "int"            NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "Attempts"                    "int"            NOT NULL,
        "StudentAnswers"            "xml"            NULL,
        "GradePercentage"            decimal(5, 2)    NULL,
        "StartedDateTime"            "datetime"        NOT NULL,
        "SubmittedDateTime"            "datetime"        NOT NULL DEFAULT(getdate()),
        CONSTRAINT "PK_Assignments_Submission_Quiz" PRIMARY KEY CLUSTERED
        (
            "QuizSubmissionID"
        ),
        CONSTRAINT "FK_Assignments_Submission_Quiz-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Quiz-Assignments" FOREIGN KEY 
        (
            "AssignmentID"
        ) REFERENCES "dbo"."Assignments" (
            "AssignmentID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Quiz-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Quiz-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        ) ON DELETE CASCADE
    )
    
    
    CREATE TABLE "Assignments_Submission_Essay" (
        "EssaySubmissionID"            "int"            IDENTITY(1, 1) NOT NULL,
        "AssignmentID"                "int"            NOT NULL,
        "UserID"                    "int"            NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "StudentAnswer"                "text"            NULL,
        "IsFinal"                    "bit"            NOT NULL DEFAULT(0),
        "Grade"                        varchar(10)        NULL,
        "TimeStamp"                    "datetime"        NOT NULL DEFAULT(getdate()),
        "SubmittedDateTime"            "datetime"        NULL,
        CONSTRAINT "PK_Assignments_Submission_Essay" PRIMARY KEY CLUSTERED
        (
            "EssaySubmissionID"
        ),
        CONSTRAINT "FK_Assignments_Submission_Essay-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Essay-Assignments" FOREIGN KEY 
        (
            "AssignmentID"
        ) REFERENCES "dbo"."Assignments" (
            "AssignmentID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Essay-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Assignments_Submission_Essay-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        ) ON DELETE CASCADE
    )
    
    CREATE TABLE "Assignments_Submission_Essay_Comments" (
        "EssaySubmissionID"            "int"            NOT NULL,
        "InstructorUserID"            "int"            NOT NULL,
        "Comment"                    "text"            NULL,
        "TimeStamp"                    "datetime"        NOT NULL DEFAULT(getdate()),
        CONSTRAINT "PK_Assignments_Submission_Essay_Comments" PRIMARY KEY CLUSTERED
        (
            "EssaySubmissionID",
            "InstructorUserID"
        ),
        CONSTRAINT "FK_Assignments_Submission_Essay_Comments-Users" FOREIGN KEY 
        (
            "InstructorUserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE
    )
    
    CREATE TABLE "Stats_Quiz_Questions" (
        "QuizSubmissionID"            "int"            NOT NULL,
        "LearnObjID"                "int"            NOT NULL,
        "QuestionID"                "int"            NOT NULL,
        "IsAnsweredCorrectly"        "bit"            NOT NULL DEFAULT(0),
        "WrongAnswer"                "text"            NULL,
        "TimeStamp"                    "datetime"        NOT NULL DEFAULT(getdate()),
        CONSTRAINT "FK_Stats_Quiz_Questions-Assignments_Submission_Quiz" FOREIGN KEY 
        (
            "QuizSubmissionID"
        ) REFERENCES "dbo"."Assignments_Submission_Quiz" (
            "QuizSubmissionID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Stats_Quiz_Questions-LearnObjs" FOREIGN KEY 
        (
            "LearnObjID"
        ) REFERENCES "dbo"."LearnObjs" (
            "LearnObjID"
        ) ON DELETE CASCADE
    )
    
    CREATE TABLE "Stats_LearnObjs" (
        "LearnObjID"                "int"            NOT NULL,
        "UserID"                    "int"            NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "StandardID"                "int"            NOT NULL,
        "ViewDateTime"                "datetime"        NOT NULL DEFAULT(getdate()),
        "ClickedDateTime"            "datetime"        NOT NULL DEFAULT(getdate()),
        CONSTRAINT "FK_Stats_LearnObjs-LearnObjs" FOREIGN KEY 
        (
            "LearnObjID"
        ) REFERENCES "dbo"."LearnObjs" (
            "LearnObjID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Stats_LearnObjs-Users" FOREIGN KEY 
        (
            "UserID"
        ) REFERENCES "dbo"."Users" (
            "UserID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Stats_LearnObjs-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_Stats_LearnObjs-Standards" FOREIGN KEY 
        (
            "StandardID"
        ) REFERENCES "dbo"."Standards" (
            "StandardID"
        ) ON DELETE CASCADE
    )
    
    CREATE TABLE "ScheduledEmailsToSend" (
        "AssignmentID"                "int"            NOT NULL,
        "EventType"                    varchar(10)        NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "SendDateTime"                "datetime"        NOT NULL,
        CONSTRAINT "PK_ScheduledEmailsToSend" PRIMARY KEY CLUSTERED
        (
            "AssignmentID",
            "EventType",
            "CourseID",
            "SectionNumber"
        ),
        CONSTRAINT "FK_ScheduledEmailsToSend-Assignments" FOREIGN KEY 
        (
            "AssignmentID"
        ) REFERENCES "dbo"."Assignments" (
            "AssignmentID"
        ) ON DELETE CASCADE,
        CONSTRAINT "FK_ScheduledEmailsToSend-Courses_Section" FOREIGN KEY 
        (
            "CourseID",
            "SectionNumber"
        ) REFERENCES "dbo"."Courses_Section" (
            "CourseID",
            "SectionNumber"
        ) ON DELETE CASCADE
    )
    
    CREATE TABLE "Maintenance" (
        "Type"                        varchar(11)        NOT NULL, /* Application or ClassPopup */
        "Message"                    "text"            NOT NULL,
        "IsEnabled"                    "bit"            NOT NULL DEFAULT(0),
        CONSTRAINT "PK_Maintenance" PRIMARY KEY CLUSTERED
        (
            "Type"
        )
    )
    
    CREATE TABLE "Evaluations" (
        "EvaluationID"                "int"            IDENTITY(1, 1) NOT NULL,
        "Name"                        varchar(100)    NOT NULL DEFAULT('Evaluation'),
        "Questions"                    "xml"            NOT NULL,
        CONSTRAINT "PK_Evaluations" PRIMARY KEY CLUSTERED
        (
            "EvaluationID"
        )
    )
    
    CREATE TABLE "Evaluations_Submissions" (
        "EvaluationID"                "int"            NOT NULL,
        "UserID"                    "int"            NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        "Answers"                    "xml"            NOT NULL,
        CONSTRAINT "PK_Evaluations_Submissions" PRIMARY KEY CLUSTERED
        (
            "EvaluationID",
            "UserID",
            "CourseID",
            "SectionNumber"
        )
    )
    
    CREATE TABLE "Relations_Evaluations-Courses_Section" (
        "EvaluationID"                "int"            NOT NULL,
        "CourseID"                    "int"            NOT NULL,
        "SectionNumber"                "int"            NOT NULL,
        CONSTRAINT "PK_Relations_Evaluations-Courses_Section" PRIMARY KEY CLUSTERED
        (
            "EvaluationID",
            "CourseID",
            "SectionNumber"
        )
    )
    
    INSERT "Standards" VALUES('Getting Started')
    INSERT "Standards" VALUES('Finding Sources')
    INSERT "Standards" VALUES('Evaluating Sources')
    INSERT "Standards" VALUES('Writing with Sources')
    
    INSERT "Maintenance" VALUES('Application', 'Application Wide Maintenance Message goes here!', 0);
    INSERT "Maintenance" VALUES('ClassPopup', 'Popup Maintenance Message goes here!', 0);
    
IF EXISTS(SELECT Username FROM Users WHERE Username = 'ileadmin')
        UPDATE Users SET AccountType = 'Admin' WHERE Username = 'ileadmin'
    ELSE
        INSERT Users VALUES('ileadmin@ile.edu', 'Admin', 'ILE', 'Admin', 'ileadmin@email.edu', '00000000', '0', 'True')
    
    INSERT Users_NonInstitute VALUES('1', 'b2ec6e8792e6603fce5ba093a96119ac627d7102', 'Organization', 'SecurityQuestion63', 'SecurityAnswer39')
    
    INSERT "Courses"
        VALUES('Smp 101 : Sample Class A', 'Why the Sample is Important!', 'Introduction', 'True')
    
    INSERT "Courses_Section"
        VALUES('1', '1', 'False', 'Section Subtitle', 'Section Introduction', 'MWF 10:10~11:00', 'True')
    
    INSERT "Courses_Section"
        VALUES('1', '2', 'True', 'Section Subtitle', 'Section Introduction', 'MW 11:10~12:00', 'True')
    
    INSERT "Courses_Section"
        VALUES('1', '4', 'False', 'Section Subtitle', 'Section Introduction', 'TuTh 13:10~14:00', 'True')
    
    
    
    INSERT "Courses"
        VALUES('Smp 102 : Sample Class B', 'Why the Sample is Important!', 'Introduction', 'True')
    
    INSERT "Courses_Section"
        VALUES('2', '1', 'False', 'Section Subtitle', 'Section Introduction', 'MWF 10:10~11:00', 'True')
    
    INSERT "Courses_Section"
        VALUES('2', '2', 'True', 'Section Subtitle', 'Section Introduction', 'MWF 11:10~12:00', 'True')
    
    
    RETURN

